<!-- @format -->

<template>
  <van-sticky>
    <div class="search_bar">
      <van-search
        v-model="searchValue"
        :placeholder="placeholder"
        @clear="handleClearSearch"
        show-action
      >
        <template #action>
          <div @click="handleSearch">搜索</div>
        </template>
      </van-search>
    </div>
  </van-sticky>
</template>

<script setup>
import { ref } from 'vue'

const emits = defineEmits(['search'])
const props = defineProps({
  placeholder: {
    type: String,
    default: '',
  },
})

const searchValue = ref('')

const handleSearch = () => {
  emits('search', searchValue.value)
}

const handleClearSearch = () => {
  searchValue.value = ''
  handleSearch()
}
</script>

<style lang="less">
.search_bar {
  .van-cell {
    padding: 0 0 !important;
  }
}
</style>
